﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BO.Management
{
    public class ServiceProvider
    {

        #region "private members"
        private const String _kInfoStoreServiceName = "InfoStore";
        private const String _kRASReportFactory ="RASReportFactory";

        private CrystalDecisions.Enterprise.EnterpriseSession _session;
        #endregion


        public ServiceProvider(LogonProvider logonProvider)
        {
            if (logonProvider == null || logonProvider.Session == null) throw new ArgumentNullException("BOE Session can't be null");
            _session = logonProvider.Session;
        }


        /// <summary>
        /// Get the infostore service which is the persistent interface to query data from BOE database 
        /// </summary>
        /// <returns></returns>
        public CrystalDecisions.Enterprise.EnterpriseService GetInfoStoreService()
        {
            return this.GetService(_kInfoStoreServiceName);
        }

        /// <summary>
        /// Get a service  
        /// </summary>
        /// <returns></returns>
        public CrystalDecisions.Enterprise.EnterpriseService GetService(String serviceName)
        {
            if (_session == null) throw new ArgumentNullException("session");
            if (String.IsNullOrEmpty(serviceName)) throw new ArgumentNullException(serviceName);
            return _session.GetService(serviceName);
        }

        public CrystalDecisions.Enterprise.EnterpriseService GetRASFactory()
        {
            return this.GetService(_kRASReportFactory);
        }
    }
}
